VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsDiemTongHop"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
Private m_sMaSV As String
Private m_sMaMH As String
Private m_dDiemL1 As Double
Private m_dDiemL2 As Double
Private m_sGhichu As String

Public Property Get masv() As String
    masv = m_sMaSV
End Property

Public Property Let masv(ByVal sMaSV As String)
    m_sMaSV = sMaSV
End Property

Public Property Get mamh() As String
    mamh = m_sMaMH
End Property

Public Property Let mamh(ByVal sMaMH As String)
    m_sMaMH = sMaMH
End Property

Public Property Get dieml1() As Double
    dieml1 = m_dDiemL1
End Property

Public Property Let dieml1(ByVal dDiemL1 As Double)
    m_dDiemL1 = dDiemL1
End Property

Public Property Get dieml2() As Double
    dieml2 = m_dDiemL2
End Property

Public Property Let dieml2(ByVal dDiemL2 As Double)
    m_dDiemL2 = dDiemL2
End Property

Public Property Get Ghichu() As String
    Ghichu = m_sGhichu
End Property

Public Property Let Ghichu(ByVal sGhichu As String)
    m_sGhichu = sGhichu
End Property

Public Function ThongKe(mamh As String, dieml1 As String, dieml2 As String) As ADODB.Recordset
    Dim sql As String
    
   On Error GoTo ThongKe_Error

    sql = "SELECT sv.MaSV, HoDem, TenSV, dth.MaMH, TenMH, dmmh.HocKy, DiemL1, DiemL2, dth.GhiChu " & _
          "FROM HSSV sv, DanhMucMonHoc dmmh, DiemTongHop dth " & _
          "WHERE sv.MaSV = dth.MaSV AND dth.MaMH = dmmh.MaMH AND " & _
            "dth.MaMH = " & IIf(mamh <> "", "'" & mamh & "'", "dth.MaMh") & " AND " & _
            "DiemL1 = " & IIf(dieml1 <> "", dieml1, "DiemL1") & " AND " & _
            "DiemL2 = " & IIf(dieml2 <> "", dieml2, "DiemL2") & " " & _
          "GROUP BY sv.MaSV, HoDem, TenSV, dth.MaMH, TenMH, dmmh.HocKy, DiemL1, DiemL2, dth.GhiChu"
    Call OpenConnection
    ' Create a Recordset by executing an SQL statement.
    Set ThongKe = g_ObjADOConn.Execute(sql)

   On Error GoTo 0
   Exit Function
ThongKe_Error:
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure ThongKe of Class Module clsDiemTongHop"
End Function

'---------------------------------------------------------------------------------------
' Procedure : SelectAll
' Date      : 27/10/2011
' Purpose   : Load danh sach tat ca record cua table co trong file du lieu
'---------------------------------------------------------------------------------------
Public Function SelectAll() As ADODB.Recordset
   On Error GoTo SelectAll_Error

    Call OpenConnection
    ' Create a Recordset by executing an SQL statement.
    Set SelectAll = g_ObjADOConn.Execute("SELECT sv.MaSV, HoDem, TenSV, dth.MaMH, TenMH, DiemL1, DiemL2, dth.GhiChu FROM HSSV sv, DanhMucMonHoc dmmh, DiemTongHop dth WHERE sv.MaSV = dth.MaSV AND dth.MaMH = dmmh.MaMH GROUP BY sv.MaSV, HoDem, TenSV, dth.MaMH, TenMH, DiemL1, DiemL2, dth.GhiChu")

   On Error GoTo 0
   Exit Function
SelectAll_Error:
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure SelectAll of Class Module clsDiemTongHop"
End Function

'---------------------------------------------------------------------------------------
' Procedure : SelectByID
' Date      : 27/10/2011
' Purpose   : Lay record cua table ung voi ma DanhMucMonHoc truyen vao
'---------------------------------------------------------------------------------------
Public Function SelectByID(ByVal masv As String, ByVal mamh As String) As ADODB.Recordset
   On Error GoTo SelectByID_Error

    Call OpenConnection
    ' Create a Recordset by executing an SQL statement.
    Set SelectByID = g_ObjADOConn.Execute("SELECT sv.MaSV, HoDem, TenSV, dth.MaMH, TenMH, DiemL1, DiemL2, dth.GhiChu FROM HSSV sv, DanhMucMonHoc dmmh, DiemTongHop dth WHERE sv.MaSV = dth.MaSV AND dth.MaMH = dmmh.MaMH AND dth.MaSV = '" & masv & "' AND dth.MaMH = '" & mamh & "'")
    
   On Error GoTo 0
   Exit Function
SelectByID_Error:
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure SelectByID of Class Module clsDiemTongHop"
End Function

'---------------------------------------------------------------------------------------
' Procedure : Insert
' Date      : 27/10/2011
' Purpose   : Them 1 record moi vao table trong file du lieu
'---------------------------------------------------------------------------------------
Public Function Insert(ByVal ObjDiemTongHop As clsDiemTongHop) As Boolean
    
   On Error GoTo Insert_Error

    Call OpenConnection
    g_ObjADOConn.Execute ("INSERT INTO DiemTongHop(MaSV, MaMH, DiemL1, DiemL2, GhiChu) " & _
                          "VALUES('" & ObjDiemTongHop.masv & "', '" & ObjDiemTongHop.mamh & "', '" & ObjDiemTongHop.dieml1 & "', '" & ObjDiemTongHop.dieml2 & "', '" & ObjDiemTongHop.Ghichu & "')")
    Call CloseConnection
    Insert = True
    
   On Error GoTo 0
   Exit Function
Insert_Error:
    Insert = False
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Insert of Class Module clsDiemTongHop"
End Function

'---------------------------------------------------------------------------------------
' Procedure : Delete
' Date      : 27/10/2011
' Purpose   : Xoa 1 record cua table trong file du lieu
'---------------------------------------------------------------------------------------
Public Function Delete(ByVal masv As String, ByVal mamh As String) As Boolean
   On Error GoTo Delete_Error

    Call OpenConnection
    g_ObjADOConn.Execute ("DELETE FROM DiemTongHop WHERE MaSV='" & masv & "' AND MaMH='" & mamh & "'")
    Call CloseConnection
    Delete = True
    
   On Error GoTo 0
   Exit Function
Delete_Error:
    Delete = False
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Delete of Class Module clsDiemTongHop"
End Function

'---------------------------------------------------------------------------------------
' Procedure : Update
' Date      : 27/10/2011
' Purpose   : Update record cua table dua tren ID truyen vao
'---------------------------------------------------------------------------------------
Public Function Update(ByVal ObjDiemTongHop As clsDiemTongHop) As Boolean
   On Error GoTo Update_Error

    Call OpenConnection
    g_ObjADOConn.Execute ("UPDATE DiemTongHop " & _
                          "SET DiemL1 = '" & ObjDiemTongHop.dieml1 & "', " & _
                              "DiemL2 = '" & ObjDiemTongHop.dieml2 & "', " & _
                              "GhiChu = '" & ObjDiemTongHop.Ghichu & "' " & _
                          "WHERE MaSV = '" & ObjDiemTongHop.masv & "' AND MaMH = '" & ObjDiemTongHop.mamh & "'")
    Call CloseConnection
    Update = True

   On Error GoTo 0
   Exit Function
Update_Error:
    Update = False
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Update of Class Module clsDiemTongHop"
End Function

